<template>
  <div class="header">
    <div class="content-wrapper">
      <div class="avatar">
        <img width="64" height="64"  :src="seller.avatar"/>
      </div>
      <div class="content">
        <div class="title">
          <span class="brand"></span>
          <span class="name">{{seller.name}}</span>
        </div>
        <div class="description">
          {{seller.description}}/{{seller.deliveryTime}}分钟送达
        </div>
        <!--由于异步操作，初始化的时候seller.supports为空,因此需要添加判断 -->
        <div v-if="seller.supports" class="supports">
          <!--动态绑定图标,通过:class的形式,将supports.type作为下标进行处理 -->
          <span class="icon" :class="classMap[seller.supports[0].type]"></span>
          <span class="text">{{seller.supports[0].description}}</span>
        </div>
      </div>
      <div v-if="seller.supports" class="support-count" @click="showDetail">
        <span class="count">{{seller.supports.length}}个</span>
        <i class="icon-keyboard_arrow_right"></i>
      </div>
    </div>
    <div class="bulletin-wrapper" @click="showDetail">
      <span class="bulletin-title"></span><span class="bulletin-text">{{seller.bulletin}}</span>
      <i class="icon-keyboard_arrow_right"></i>
    </div>
    <!--设置背景色 -->
    <div class="background">
      <img :src="seller.avatar" width="100%" height="100%" alt=""/>
    </div>
    <!--商家详情 & 渐变效果-->
    <transition name="fade">
    <div v-show="detailShow" class="detail">
      <div class="detail-wrapper clearfix">
        <div class="detail-main">
          <h1 class="name">{{seller.name}}</h1>
          <div class="star-wrapper">
            <star :size="48" :score="seller.score"></star>
          </div>
          <!--自适应flex布局 -->
          <div class="title">
            <div class="line"></div>
            <div class="text">优惠信息</div>
            <div class="line"></div>
          </div>
          <!--ul列表循环 -->
          <ul v-if="seller.supports" class="supports">
            <li v-for="(item,index) in seller.supports"  :key="index" class="support-item">
              <span class="icon" :class="classMap[seller.supports[index].type]"></span>
              <span class="text">{{seller.supports[index].description}}</span>
            </li>
          </ul>
          <!--自适应flex布局 -->
          <div class="title">
            <div class="line"></div>
            <div class="text">商家公告</div>
            <div class="line"></div>
          </div>
          <div class="bulletin">
            <p class="content">{{seller.bulletin}}</p>
          </div>
        </div>
      </div>
      <div class="detail-close" @click="hideDetail">
        <i class="icon-close"></i>
      </div>
    </div>
    </transition>
  </div>
</template>
<script>            
import star from '../../components/base/star/star';
export default {
  props: {
    seller: {
      type: Object
    }
  },
  data() {
    return {
      detailShow: false
    };
  },
  components: {
    star
  },
  created() {
    // 控制样式
    this.classMap = ['decrease', 'discount', 'special', 'invoice', 'guarantee'];
  },
  methods: {
    showDetail() {
      this.detailShow = true;
    },
    hideDetail() {
      this.detailShow = false;
    }
  }
};
</script>
<style lang="scss" rel="stylesheet/scss">
  @import "../../assets/style/mixin.scss";

.header{
  position: relative;//由于class='background'存在绝对定位,因此需要设置父元素为相对定位
  overflow: hidden;
  color: #fff;
  // background: #999;//设置背景色,这个没有存在的意思
  background:rgba(7, 17, 27, 0.2);
  .content-wrapper {
    position: relative;
    padding: 24px 12px 18px 24px;
    font-size: 0; //  由于avatar与content之间有空格字符,解决方法，设置父元素的font-size：0
    .avatar {
      display: inline-block;
      vertical-align: top;
      img {
        border-radius: 2px;
      }
    }
    .content {
      display: inline-block;
      margin-left: 16px;
      .title {
        margin: 2px 0 8px 0;
        .brand {
          vertical-align: top;
          display: inline-block;//由于没有内容,设置宽高无效果,需要dispaly:inline-block进行占空位
          width: 30px;
          height: 18px;
          @include bg-img('brand');
          background-size: 30px 18px;
          background-repeat: no-repeat;
        }
        .name {
          vertical-align: top;
          margin-left: 6px;
          line-height: 18px;
          font-size: 16px;
          font-weight: bold;
        }
      }
      .description {
        margin-bottom: 10px ;
        line-height: 12px;
        font-size: 12px;
      }
      .supports {
        .icon {
          vertical-align: top;
          display: inline-block;
          width: 12px;
          height: 12px;
          margin-right: 4px;
          background-size: 12px 12px;
          background-repeat: no-repeat;
          &.decrease {
            @include bg-img('decrease_1')
          }
          &.discount {
            @include bg-img('discount_1')
          }
          &.guarantee {
            @include bg-img('guarantee_1')
          }
          &.invoice {
            @include bg-img('invoice_1')
          }
          &.special {
            @include bg-img('special_1')
          }
        }
        .text {
          vertical-align: top;
          line-height: 12px;
          font-size: 10px;
        }
      }
    }
    .support-count {
       position: absolute;//子元素绝对定位,父元素则进行相对定位
       right: 12px;//right指向div距离右边的宽度,而不是div中的span距离右边的宽度
       bottom: 14px;//bottom指向div
       padding: 0 8px;//上下为0px,左右为8px
       height: 24px;
       line-height: 24px;
       border-radius: 14px;
       background: rgba(0,0,0,0.2);
       text-align: center;
       .count {
         vertical-align: top;//由于设置了垂直居中,需要将arrow_right中重新设置line-height的高度
         font-size: 10px;
       }
       .icon-keyboard_arrow_right {
         margin-left: 2px;
         line-height: 24px;
         font-size: 10px;
       }
    }
  }
  .bulletin-wrapper {
    position: relative;
    padding: 0 22px 0 12px;
    height: 28px;
    line-height: 28px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: rgba(0,0,0,0.2);
    .bulletin-title {
      display: inline-block;//首先需要布局display的格局
      vertical-align: top;//由于设置了vertical-align，则需要重新设置margin-top的高度
      margin-top: 8px;//(28px-12px)/2
      width: 22px;
      height: 12px;
      @include bg-img('bulletin');
      background-size: 22px 12px;
      background-repeat: no-repeat;
    }
    .bulletin-text {
      vertical-align: top;
      font-size: 10px;
      margin: 0 4px;
    }
    .icon-keyboard_arrow_right {
      position: absolute;
      font-size: 10px;
      right: 0px;
      margin: 8px;
    }
  }
  .background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    filter: blur(10px);// 背景图的滤镜效果,则父元素需要添加透明度rgba
  }
  .detail {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    background:rgba(7, 17, 27, 0.8); 
    width: 100%;
    height: 100%;
    overflow: auto;// 内容超过可以进行滚动,使用hidden则不可以滚动
    transition: all .5s;// 切记不是 transform
    opacity: 1;// 透明度
    background: rgba(7, 17, 27, 0.8);
    -webkit-backdrop-filter: blur(5px);//针对ios浏览器
    &.fade-enter-active, &.fade-leave-active {
      transition: all .5s;
    }
    &.fade-enter, &.fade-leave-active {
      opacity: 0;
      background: rgba(7, 17, 27, 0);
    } // fade-enter,fade-enter-active实现渐变效果
    .detail-wrapper {
      min-height: 100%;
      width: 100%;
      .detail-main {
        margin-top: 64px;
        padding-bottom: 64px;
        .name {
         line-height: 16px;
         text-align: center;
         font-size: 16px;
         font-weight: 700;
        }
        .star-wrapper {
          text-align: center;
          margin-top:16px;
          padding: 2px 0;
        }
        .title {
          display: flex;//父元素flex布局,子元素flex设置为1,同时设置position: relative;
          width: 80%;
          margin: 28px auto 24px auto;
          .line {
            flex: 1;
            position: relative;
            top: -6px;
            border-bottom: 1px solid rgba(255,255,255,0.2);
          }
          .text {
            padding: 0 12px;
            font-size: 14px;
            font-weight: 700;
          }
        }
        .supports {
          width: 80%;
          margin: 0 auto;
          .support-item {
            padding: 0 12px;
            margin-bottom: 12px;
            font-size: 0;//缩进icon与text之间的占位空格符
            &.last-child {
              margin-bottom: 0px;
            }
            .icon {
              display: inline-block;//span首先设置display布局
              vertical-align: top;
              width: 16px;
              height: 16px;
              margin-right: 6px;
              background-size: 16px 16px;
              background-repeat: no-repeat;
              &.decrease {
                  @include bg-img('decrease_2');// 图片没有展示出来因为没有导入
              }
              &.discount {
                  @include bg-img('discount_2');
              }
              &.guarantee {
                  @include bg-img('guarantee_2');
              }
              &.invoice {
                  @include bg-img('invoice_2');
              }
              &.special {
                  @include bg-img('special_2');
              }
            }
            .text {
              vertical-align: top;
              line-height: 16px;
              font-size: 12px;
            }
          }
        }
        .bulletin {
          width: 80%;
          margin: 0 auto;
          .content {
            padding: 0 12px;
            font-size: 12px;
            line-height: 24px;
          }
        }
      }
    }
    .detail-close {
      position: relative;
      width: 32px;
      height: 32px;
      margin: -64px auto 0 auto;
      clear: both;//
      font-size: 32px;
    }
  }
}
</style>

